package cn.com.smartdevices.bracelet.chart;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.graphics.drawable.BitmapDrawable;

import com.goodving.guli.R;
import com.goodving.guli.utility.C1481u;
import com.goodving.guli.view.BitmapDescriptorFactory;

import cn.com.smartdevices.bracelet.chart.base.PieChart;
import cn.com.smartdevices.bracelet.chart.util.C0804t;


/* renamed from: cn.com.smartdevices.bracelet.chart.w */
public class XMDynamicWeightViewUnit extends PieChart { // C0806w
    private static final float mFloatA = 15.0f;
    private static final float mFloatB = 16.33f;
    private Paint mRectFA;
    private float mFloatC;
    private RectF mRectFX;
    private RectF mRectFY;
    private RectF mRectFZ;
    private float mFloatD;
    private float mFloatE;
    private float mFloatF;
    private Bitmap mBitMap;
    private Paint mPaintX;
    private Paint mPaintY;
    private Paint mPaintZ;

    public XMDynamicWeightViewUnit(Context context) {
        super(context);
        this.mBitMap = ((BitmapDrawable) context.getResources().getDrawable(R.drawable.ic_dynamic_weight)).getBitmap();
        this.mPaintX = new Paint(1);
        this.mPaintY = new Paint(1);
        this.mPaintZ = new Paint(1);
        this.mPaintX.setColor(0x80ffffff);
        this.mPaintX.setStrokeWidth(this.mDensity * mFloatA);
        this.mPaintX.setStyle(Style.STROKE);
        this.mPaintY.setColor(1308622847);
        this.mPaintY.setStrokeWidth(this.mDensity * mFloatA);
        this.mPaintY.setStyle(Style.STROKE);
        this.mPaintZ.setColor(-1);
        this.mPaintZ.setStrokeWidth(2.0f * this.mDensity);
        this.mPaintZ.setStyle(Style.STROKE);
        this.mFloatC = mFloatB * this.mDensity;
        this.mRectFA = new Paint(1);
        this.mRectFA.setColor(1308622847);
        this.mRectFA.setStrokeWidth(1.0f);
        this.mRectFA.setStyle(Style.STROKE);
        this.mFloatD = 135.0f;
        this.mFloatE = BitmapDescriptorFactory.HUE_VIOLET;
    }

    protected void drawPie(Canvas canvas, RectF rectF, float f, float f2, float f3, float f4, float f5) { //m8841a
        canvas.drawArc(this.mRectFY, this.mFloatD, (this.mFloatE / 2.0f) - 7.0f, false, this.mRectFA);
        canvas.drawArc(this.mRectFY, (this.mFloatD + (this.mFloatE / 2.0f)) + 7.0f, (this.mFloatE / 2.0f) - 7.0f, false, this.mRectFA);
        float f6 = this.mDensityScale;
        if (C0804t.m8835a()) {
            f6 = (float) (((double) f6) * 0.88d);
        }
        C0804t.m8830a(canvas, this.mRectFZ.centerX(), this.mRectFZ.centerY(), f6, this.mBitMap, null);
        float f7 = (this.mFloatE * f4) * f5;
        canvas.drawArc(this.mRectFX, this.mFloatD, this.mFloatE, false, this.mPaintY);
        if (f7 > 0.0f) {
            canvas.drawArc(this.mRectFX, this.mFloatD, f7, false, this.mPaintX);
        }
        if (this.mFloatF > 0.0f && this.mFloatF <= this.mMaxValue) {
            float f8 = f3 - (this.mFloatC * 2.0f);
            float f9 = f8 - (mFloatA * this.mDensity);
            float f10 = (float) (((double) ((((this.mFloatE * (this.mFloatF / this.mMaxValue)) + (90.0f + this.mFloatD)) / 360.0f) * 2.0f)) * 3.141592653589793d);
            Canvas canvas2 = canvas;
            canvas2.drawLine((float) (((double) f) + (Math.sin((double) f10) * ((double) f8))), (float) (((double) f2) - (((double) f8) * Math.cos((double) f10))), (float) (((double) f) + (Math.sin((double) f10) * ((double) f9))), (float) (((double) f2) - (((double) f9) * Math.cos((double) f10))), this.mPaintZ);
        }
    }

    protected void onRectChanged(RectF rectF) { // m8842a
        super.onRectChanged(rectF);
        this.mRectFX = new RectF(rectF);
        RectF rectF2 = this.mRectFX;
        rectF2.left += (this.mFloatC * 2.0f) + ((this.mDensity * mFloatA) / 2.0f);
        rectF2 = this.mRectFX;
        rectF2.top += (this.mFloatC * 2.0f) + ((this.mDensity * mFloatA) / 2.0f);
        rectF2 = this.mRectFX;
        rectF2.right -= (this.mFloatC * 2.0f) + ((this.mDensity * mFloatA) / 2.0f);
        rectF2 = this.mRectFX;
        rectF2.bottom -= (this.mFloatC * 2.0f) + ((this.mDensity * mFloatA) / 2.0f);
        this.mRectFY = new RectF(rectF);
        rectF2 = this.mRectFY;
        rectF2.left += this.mFloatC;
        rectF2 = this.mRectFY;
        rectF2.top += this.mFloatC;
        rectF2 = this.mRectFY;
        rectF2.right -= this.mFloatC;
        rectF2 = this.mRectFY;
        rectF2.bottom -= this.mFloatC;
        this.mRectFZ = new RectF();
        this.mRectFZ.left = rectF.centerX() - (15.5f * this.mDensity);
        this.mRectFZ.top = rectF.top + (this.mDensity * 2.0f);
        this.mRectFZ.right = this.mRectFZ.left + (this.mDensity * 31.0f);
        this.mRectFZ.bottom = this.mRectFZ.top + (this.mDensity * 31.0f);
    }

    public void m8843b(float f) {
        this.mFloatF = f;
    }

    public void setScaleIcon(int f) {

        if (f == R.drawable.ic_dynamic_weight) {
            this.mBitMap = ((BitmapDrawable) C1481u.getContext().getResources().getDrawable(f)).getBitmap();
        } else {
            this.mBitMap = small(((BitmapDrawable) C1481u.getContext().getResources().getDrawable(f)).getBitmap());
        }
    }

    private static Bitmap big(Bitmap bitmap) {
        Matrix matrix = new Matrix();
        matrix.postScale(1.1f,1.1f); //长和宽放大缩小的比例
        Bitmap resizeBmp = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
        return resizeBmp;
    }

    private static Bitmap small(Bitmap bitmap) {
        Matrix matrix = new Matrix();
        matrix.postScale(0.7f,0.7f); //长和宽放大缩小的比例
        Bitmap resizeBmp = Bitmap.createBitmap(bitmap,0,0,bitmap.getWidth(),bitmap.getHeight(),matrix,true);
        return resizeBmp;
    }
}
